/**
 * Created by fld on 2021/6/17.
 */
$('.reset-btn').click(function(){
    var url = $(this).parents('form').attr('action');
    location.href = url;
})

$('.submitForm').click(function(){
    var form = $(this).parents('form');
    loadIndex = layer.load(2);
    $.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize(),
        dataType: 'json',
        success: function(result){
            layer.close(loadIndex);
            if(result.status){
                layer.msg(result.message, {
                    time: 1000,
                    icon: 6,
                    end: function () {
                        layer.closeAll();
                        location.href = result.data.url;
                    }
                });
            }else{
                layer.msg(result.message, {
                    icon: 5,
                    time: 2000
                });
            }
        }
    });
})

$('.del-btn').click(function(){
    var url = $(this).attr('data-href');
    var confirm_msg = $(this).attr('data-confirm');
    var id = $(this).attr('data-id');

    layer.confirm(confirm_msg, {
        btn: ['确定删除','取消'] //按钮
    }, function(){
        loadIndex = layer.load(2);
        $.ajax({
            type: 'post',
            url: url,
            data: {id:id},
            dataType: 'json',
            success: function(result){
                layer.close(loadIndex);
                if(result.status){
                    layer.msg(result.message, {
                        time: 1000,
                        icon: 6,
                        end: function () {
                            layer.closeAll();
                            location.href = result.data.url;
                        }
                    });
                }else{
                    layer.msg(result.message, {
                        icon: 5,
                        time: 2000
                    });
                }
            }
        });
    }, function(){
        layer.closeAll();
    });
})

$('.action-btn').click(function(){
    var url = $(this).attr('data-href');
    var confirm_msg = $(this).attr('data-confirm');
    var id = $(this).attr('data-id');

    layer.confirm(confirm_msg, {
        btn: ['确定','取消'] //按钮
    }, function(){
        loadIndex = layer.load(2);
        $.ajax({
            type: 'post',
            url: url,
            data: {id:id},
            dataType: 'json',
            success: function(result){
                layer.close(loadIndex);
                if(result.status){
                    layer.msg(result.message, {
                        time: 1000,
                        icon: 6,
                        end: function () {
                            layer.closeAll();
                            location.href = result.data.url;
                        }
                    });
                }else{
                    layer.msg(result.message, {
                        icon: 5,
                        time: 2000
                    });
                }
            }
        });
    }, function(){
        layer.closeAll();
    });
})

$('.change_status').click(function(){
    var url = $(this).attr('data-href');
    var val = $(this).attr('data-val');
    var ids_array = new Array();
    $("input[name='ids']:checked").each(function() {
        ids_array.push($(this).val());
    });
    if(ids_array.length == 0){
        layer.msg('请选择要操作的数据', {
            icon: 5,
            time: 2000
        });
        return false;
    }
    var ids_str = ids_array.join(',');
    loadIndex = layer.load(2);
    $.ajax({
        type: 'post',
        url: url,
        data: {'val': val,'ids': ids_str},
        dataType: 'json',
        success: function(result){
            layer.close(loadIndex);
            if(result.status){
                layer.msg(result.message, {
                    time: 1000,
                    icon: 6,
                    end: function () {
                        layer.closeAll();
                        location.href = result.data.url;
                    }
                });
            }else{
                layer.msg(result.message, {
                    icon: 5,
                    time: 2000
                });
            }
        }
    });
})

$('#queryBtn').click(function(){
    var data_id = $(this).attr('data-id');
    var url = $(this).attr('data-href')+'?data_id='+data_id;
    layer.open({
        type: 2,
        title: '选择商户',
        area: ['1000px', '600px'],
        fixed: false, //不固定
        maxmin: true,
        content: url
    });
})


$('.closeBtn').click(function(){
    layer.closeAll();
})

$('.page-link').click(function(){
    var url = $(this).attr('data-href');
    if(url != ''){
        $('.search-bar').attr('action', url);
        $('.search-bar').submit();
    }
})
$('.file_upload .file').change(function(){
	var id = $(this).attr('data-showid');
	$('#'+id).val($(this).val());
})